<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.contactName$lk" placeholder="联系人" clearable class="filter-item" />
      <el-input v-model="listQuery.contactMobile$lk" placeholder="联系电话" clearable class="filter-item" />
      <el-input v-model="listQuery.name$lk" placeholder="产品名称" clearable class="filter-item" />
      <el-select v-model="listQuery.status" placeholder="状态" clearable class="filter-item">
        <el-option v-for="item in statusJson" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"
        >
        查询
      </el-button>
      <el-button class="filter-item" type="warning" icon="el-icon-sort" @click="handlePlRead"
        >
        批量确认
      </el-button>
      <el-button class="filter-item" type="danger" icon="el-icon-delete" @click="handlePlDelete"
        >
        批量删除
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row row-key="id" style="width: 100%;"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" />
      <el-table-column label="序号" type="index" align="center" width="60px" />
      <el-table-column label="产品名称" prop="name" align="center" />
      <el-table-column label="产品数量" prop="num" align="center" />
      <el-table-column label="产品单位" prop="unit" align="center" />
      <el-table-column label="联系人" prop="contactName" align="center" />
      <el-table-column label="联系电话" prop="contactMobile" align="center" />
      <el-table-column label="详细说明" prop="remark" align="center" />
      <!-- <el-table-column label="附件" prop="file" align="center" /> -->
      <el-table-column label="附件" prop="file" align="center">
        <template slot-scope="{row}">
          <a download :href="row.file" v-if="row.file" style="color:#1890ff">立即下载</a>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="statusText" align="center" />
      <!-- <el-table-column label="创建时间" prop="createTime" align="center" /> -->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { enquiryPageByQo, enquiryRemoveByIds, enquiryRead } from '@/api/mall'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination'
export default {
  name: 'Feedback',
  directives: { waves },
  components: { Pagination },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        pageNo: 1,
        pageSize: 20,
        contactName$lk: '',
        name$lk: '',
        contactMobile$lk: '',
        status: ''
      },
      multipleSelection: [],
      statusJson: [
        { value: 0, label: '未确认' },
        { value: 1, label: '已确认' }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      enquiryPageByQo(this.listQuery).then(response => {
        this.list = response.list || []
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    },
    // 批量操作
    handleSelectionChange(val) {
      this.multipleSelection = val.map((ele) => {
        return ele.id
      })
    },
    handlePlDelete() {
      if (!this.multipleSelection || this.multipleSelection.length < 1) {
        this.$message.error('请至少选择一条数据')
        return
      }
      const params = {
        ids: this.multipleSelection.join(',')
      }
      this.$confirm('是否继续删除？').then(() => {
        enquiryRemoveByIds(params).then(() => {
          // this.$notify({
          //   title: '成功',
          //   message: '批量删除成功！',
          //   type: 'success',
          //   duration: 2000
          // })

          this.$message({
            message: '批量删除成功！',
            type: 'success'
          });
          this.getList()
        })
      })
    },
    handlePlRead() {
      if (!this.multipleSelection || this.multipleSelection.length < 1) {
        this.$message.error('请至少选择一条数据')
        return
      }
      const params = {
        ids: this.multipleSelection.join(',')
      }
      this.$confirm('是否继续操作？').then(() => {
        enquiryRead(params).then(() => {
          // this.$notify({
          //   title: '成功',
          //   message: '操作成功！',
          //   type: 'success',
          //   duration: 2000
          // })

          this.$message({
            message: '操作成功！',
            type: 'success'
          });
          this.getList()
        })
      })
    },
  }
}
</script>
